package org.minbox.framework.command.execute;

import java.util.Locale;

/**
 * The operating system tag define
 * Provide definitions of common operating systems
 * The {@link #isOs(String)} method can be used to determine whether the current operating system matches the given os name
 *
 * @author 恒宇少年
 */
public class OperatingSystem {
    /**
     * apple mac osx operating system
     */
    public static final String MAC_OSX = "mac";
    /**
     * microsoft windows operating system
     */
    public static final String WINDOWS = "windows";
    /**
     * linux operating system
     */
    public static final String LINUX = "linux";
    /**
     * current operating system name
     * use {@link System#getProperty(String)} get os name
     */
    public static final String CURRENT_OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US);

    /**
     * Verify that the current operating system is the specified operating system
     *
     * @param os specified operating system
     * @return Return true when matching
     */
    public static boolean isOs(String os) {
        if (os == null || os.length() <= 0) {
            throw new RuntimeException("specified operating system is null");
        }
        return CURRENT_OS_NAME.indexOf(os) >= 0;
    }
}
